package com.s63.appinfo.controller;

import com.s63.appinfo.pojo.AjaxResult;
import com.s63.appinfo.pojo.AppVersion;
import com.s63.appinfo.service.AppVersionService;
import com.s63.appinfo.util.FileUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.io.IOException;
import java.util.List;

@RestController
@RequestMapping("/appVersion")
public class AppVersionController {
    @Autowired
    private AppVersionService appVersionService;

    @GetMapping("/getByAppId/{appId}")
    public AjaxResult getByAppId(@PathVariable Long appId) {
        List<AppVersion> list = appVersionService.getByAppId(appId);
        return AjaxResult.ok(list);
    }

    @PostMapping
    public AjaxResult add(AppVersion appVersion, MultipartFile file) throws IOException {
        String filename = FileUtils.saveFile(file);
        appVersion.setApkFileName(filename);
        boolean success = appVersionService.save(appVersion);
        return AjaxResult.ok(success);
    }
}
